package com.dingzhen.utils;


import com.dingzhen.enums.StatusCodeEnum;

public class ResultSet<T> {

    /**
     * 返回的状态码
     */
    private Integer resultCode;

    /**
     * 返回的消息
     */
    private String resultMsg;

    /**
     * 返回的数据
     */
    private T data;

    public ResultSet() {
    }

    public ResultSet(StatusCodeEnum resultCode, String resultMsg) {
        this.resultCode = resultCode.getCode();
        this.resultMsg = resultMsg;
    }

    public ResultSet(StatusCodeEnum resultCode, String resultMsg, T data) {
        this.resultCode = resultCode.getCode();
        this.resultMsg = resultMsg;
        this.data = data;
    }

    /**
     * 返回成功的消息
     *
     * @param resultMsg
     * @return
     */

    public static ResultSet success(String resultMsg) {
        return new ResultSet(StatusCodeEnum.SUCCESS, resultMsg);
    }

    /**
     * 返回成功的消息和数据
     *
     * @param resultMsg
     * @param data
     * @return
     */
    public static <T> ResultSet success(String resultMsg, T data) {
        return new ResultSet<T>(StatusCodeEnum.SUCCESS, resultMsg, data);
    }

    /**
     * 返回失败的消息
     *
     * @param resultMsg
     * @return
     */
    public static ResultSet error(String resultMsg) {
        return new ResultSet(StatusCodeEnum.ERROR, resultMsg);
    }

    /**
     * 返回失败的消息和数据
     *
     * @param resultMsg
     * @param data
     * @return
     */
    public static <T> ResultSet error(String resultMsg, T data) {
        return new ResultSet(StatusCodeEnum.ERROR, resultMsg, data);
    }

    /**
     * 是否成功
     *
     * @return
     */
    public boolean isSuccess() {
        return StatusCodeEnum.SUCCESS.getCode() == this.getResultCode();
    }

    public Integer getResultCode() {
        return resultCode;
    }

    public void setResultCode(Integer resultCode) {
        this.resultCode = resultCode;
    }

    public String getResultMsg() {
        return resultMsg;
    }

    public void setResultMsg(String resultMsg) {
        this.resultMsg = resultMsg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
